﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace Urbania.Utilities
{
    public class Camera
    {
        protected Vector2 position;
        protected Vector2 screen;
        protected Matrix transform;
        protected float zoom;
        protected int mouseWheelVal;

        public Vector2 Position { get { return this.position; } }

        public Matrix Transform
        {
            get
            {
                this.transform = Matrix.CreateTranslation(new Vector3(-this.position.X, -this.position.Y, 0))
                    * Matrix.CreateScale(zoom)
                    * Matrix.CreateTranslation(new Vector3(screen.Y * 0.5f, screen.X * 0.5f, 0));
                return this.transform;
            }
        }

        public Camera(Vector2 position, GraphicsDevice device)
        {
            this.position = position;
            this.screen = new Vector2(device.Viewport.Width, device.Viewport.Height);
            this.zoom = 1.0f;
        }

        public void Update(GameTime gameTime, MouseState mouse)
        {
            if (mouse.X >= this.screen.X - 30)
                this.position.X += 2;
            else if (mouse.X <= 30)
                this.position.X -= 2;

            if (mouse.Y >= this.screen.Y - 30)
                this.position.Y += 2;
            else if (mouse.Y <= 30)
                this.position.Y -= 2;

            if (mouse.ScrollWheelValue > this.mouseWheelVal)
                zoom++;
            else if(mouse.ScrollWheelValue < this.mouseWheelVal)
                zoom--;
        }
    }
}
